//
//  ICMAppointmentBasicInfoView.m
//  ICrEAM
//
//  Created by rainimute on 16/11/2.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMAppointmentBasicInfoView.h"
#import "SelectAreaPrefixView.h"
#import "ICMBasicInfoModel.h"
#import "ICMAppointmentOtherInfoModel.h"
#import "ICMInputAreaView.h"
#import "ICMAppointmentBasicInfoModel.h"

#define xDistanceA                  ActualWidth(25)
#define xDistanceB                  ActualWidth(50)
#define yDistance                   (ScreenHeight-240-6*TitleTFViewHeight)/8
#define TitleTFViewHeight           ActualHeight(63)
#define TitleTViewHeight            ActualHeight(90)


@interface ICMAppointmentBasicInfoView ()<SelectAreaPrefixViewDelegate,ICMTitleTextFeildViewDelegate,ICMInputAreaViewDelegate>


@property (nonatomic, strong) TPKeyboardAvoidingScrollView *bigScrollView;

@property (nonatomic, strong) SelectAreaPrefixView *selectAreaPrefixView;

//车牌号选择其他后弹出的输入界面
@property (nonatomic, strong) ICMInputAreaView *inputAreaView;

@property (nonatomic, strong) UITapGestureRecognizer *tap;

@end

@implementation ICMAppointmentBasicInfoView

#pragma mark    初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self){
        self.backgroundColor = BackgroundColor_White;
        self.haveChangeVIN = YES;
        self.bigScrollView = [[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-240)];
        self.bigScrollView.backgroundColor = [UIColor clearColor];
        //第一行
        ICMTitleTextFeildView *vinNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(ActualWidth(20), yDistance, ActualWidth(220), TitleTFViewHeight) title:@"VIN"];
        vinNumberView.limitedNum = 17;
        vinNumberView.delegate = self;
//        vinNumberView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:vinNumberView];
        
        ICMTitleTextFeildView *selectAreaView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(vinNumberView.rightEdge+xDistanceA, vinNumberView.y, ActualWidth(65), TitleTFViewHeight) title:@"车牌号" addTarget:self selector:@selector(clickSelectAreaView:)];
        selectAreaView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:selectAreaView];
        
        ICMTitleTextFeildView *plateNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(selectAreaView.rightEdge, selectAreaView.y, ActualWidth(155), TitleTFViewHeight) title:@" "];
        plateNumberView.contentTextFeild.keyboardType = UIKeyboardTypeDefault;
        plateNumberView.delegate = self;
        //        plateNumberView.limitedNum = 7;
        plateNumberView.contentTextFeild.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

//        plateNumberView.contentTextFeild.placeholder = @"请选择";
        [self.bigScrollView addSubview:plateNumberView];
        
        ICMTitleTextFeildView *ownerNameView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(plateNumberView.rightEdge+xDistanceB, plateNumberView.y, ActualWidth(465), TitleTFViewHeight) title:@"车主姓名"];
//        ownerNameView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:ownerNameView];
        
        self.vinNumberView = vinNumberView;
        self.vinNumberView.isUppercase = YES;
        self.selectAreaView = selectAreaView;
        self.plateNumberView = plateNumberView;
        self.plateNumberView.isUppercase = YES;
        self.ownerNameView = ownerNameView;
        //第一行点击小图标
        UIButton *carInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        carInfoBtn.frame = CGRectMake(ActualWidth(390), selectAreaView.y, ActualWidth(23), ActualWidth(23));
        [carInfoBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_CarInfo] selectedBackImage:nil actionSEL:@selector(clickCarInfoBtn) target:self];
        [self.bigScrollView addSubview:carInfoBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:carInfoBtn andSEL:@selector(clickCarInfoBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        UIButton *monitorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        monitorBtn.frame = CGRectMake(ActualWidth(460), selectAreaView.y, ActualWidth(23), ActualWidth(23));
        [monitorBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_CarMonitor] selectedBackImage:nil actionSEL:@selector(clickMonitorBtn) target:self];
        [self.bigScrollView addSubview:monitorBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:monitorBtn andSEL:@selector(clickMonitorBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        UIButton *carOwnerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        carOwnerBtn.frame = CGRectMake(ActualWidth(965), selectAreaView.y, ActualWidth(23), ActualWidth(23));
        [carOwnerBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_CarOwner] selectedBackImage:nil actionSEL:@selector(clickCarOwnerBtn) target:self];
        [self.bigScrollView addSubview:carOwnerBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:carOwnerBtn andSEL:@selector(clickCarOwnerBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        //第二行
        ICMTitleTextFeildView *invoiceDateView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(vinNumberView.x, vinNumberView.bottomEdge+yDistance, ActualWidth(220), TitleTFViewHeight) title:@"购车发票日期"];
//        invoiceDateView.contentTextFeild.placeholder = @"必填";
        invoiceDateView.btnEnAble = YES;
        [self.bigScrollView addSubview:invoiceDateView];
        
        ICMTitleTextFeildView *currentMileageView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(invoiceDateView.rightEdge+xDistanceA, invoiceDateView.y, ActualWidth(220), TitleTFViewHeight) title:@"当前行驶里程(KM)"];
//        currentMileageView.contentTextFeild.placeholder = @"必填";
        currentMileageView.contentTextFeild.keyboardType=UIKeyboardTypeNumberPad;
        [self.bigScrollView addSubview:currentMileageView];
        
        ICMTitleTextFeildView *ownerPhoneNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(currentMileageView.rightEdge+xDistanceB, currentMileageView.y, ActualWidth(220), TitleTFViewHeight) title:@"车主手机"];
        [self.bigScrollView addSubview:ownerPhoneNumberView];
        
        ICMTitleTextFeildView *ownerTypeView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(ownerPhoneNumberView.rightEdge+xDistanceA, ownerPhoneNumberView.y, ActualWidth(220), TitleTFViewHeight) title:@"车主性质"];
        [self.bigScrollView addSubview:ownerTypeView];
        
        self.invoiceDateView = invoiceDateView;
        self.currentMileageView = currentMileageView;
        self.ownerPhoneNumberView = ownerPhoneNumberView;
        self.ownerTypeView = ownerTypeView;
        
        //第三行
        ICMTitleTextFeildView *carTypeView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(invoiceDateView.x, invoiceDateView.bottomEdge+yDistance, (CGRectGetMaxX(currentMileageView.frame)-invoiceDateView.x), TitleTFViewHeight) title:@"车型"];
//        carTypeView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:carTypeView];
        
        ICMTitleTextFeildView *customerNameView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(ownerPhoneNumberView.x, carTypeView.y, ActualWidth(220), TitleTFViewHeight) title:@"预约人姓名"];
        customerNameView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:customerNameView];
        
        ICMTitleTextFeildView *customerPhoneNumberView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(customerNameView.rightEdge+xDistanceA, customerNameView.y, ActualWidth(220), TitleTFViewHeight) title:@"预约人手机"];
        customerPhoneNumberView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:customerPhoneNumberView];
        
        self.carTypeView = carTypeView;
        self.customerNameView = customerNameView;
        self.customerPhoneNumberView = customerPhoneNumberView;
        
        //第四行
        self.appointmentTypeView = [ICMTitleTextFeildView createNoneditableICMTitleTextFeildViewWithFrame:CGRectMake(carTypeView.x, carTypeView.bottomEdge+2*yDistance, ActualWidth(220), TitleTFViewHeight) title:@"预约业务类型"];
        self.appointmentTypeView.contentText = @"维修";
        [self.bigScrollView addSubview:self.appointmentTypeView];
        
        self.appointmentSubTypeView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(self.appointmentTypeView.rightEdge+xDistanceA, self.appointmentTypeView.y, self.appointmentTypeView.width, TitleTFViewHeight) title:@"预约业务子类型" addTarget:self selector:@selector(clickRepairType)];
        self.appointmentSubTypeView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:self.appointmentSubTypeView];
        
        self.pickUpAddressView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(self.appointmentSubTypeView.rightEdge+xDistanceB, self.appointmentSubTypeView.y, carTypeView.width, TitleTFViewHeight) title:@"接车地址"];
        [self.bigScrollView addSubview:self.pickUpAddressView];
        
        
        //第五行
        self.stepInTimeView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(CGRectGetMinX(self.appointmentTypeView.frame), self.appointmentTypeView.bottomEdge+yDistance, CGRectGetWidth(self.appointmentTypeView.frame), TitleTFViewHeight) title:@"预约进站时间" addTarget:self selector:@selector(stepInTimeViewDidSelected:)];
        self.stepInTimeView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:self.stepInTimeView];
        
        self.serviceAdvisorView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(self.stepInTimeView.rightEdge+xDistanceA, CGRectGetMinY(self.stepInTimeView.frame), CGRectGetWidth(self.stepInTimeView.frame), TitleTFViewHeight) title:@"预约服务顾问" addTarget:nil selector:nil];
        self.serviceAdvisorView.contentTextFeild.placeholder = @"必填";
        [self.bigScrollView addSubview:self.serviceAdvisorView];
        
        self.sendCarAddressView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake(self.serviceAdvisorView.rightEdge+xDistanceB, CGRectGetMinY(self.serviceAdvisorView.frame), CGRectGetWidth(self.pickUpAddressView.frame), TitleTFViewHeight) title:@"送车地址"];
        [self.bigScrollView addSubview:self.sendCarAddressView];
        //第五行点击小图标  日历
        UIButton *calenderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        calenderBtn.frame = CGRectMake(self.stepInTimeView.rightEdge-ActualWidth(23)-5, self.stepInTimeView.y, ActualWidth(23), ActualWidth(23));
        [calenderBtn setUpButtonWithNormolTitle:nil selectedTitle:nil normolTitleSize:0 selectedTitleSize:0 normolTitleColor:nil selectedTitleColor:nil normolBcakImage:[UIImage imageNamed:Appointment_Calendar] selectedBackImage:nil actionSEL:@selector(clickCalenderBtn) target:self];
        [self.bigScrollView addSubview:calenderBtn];
        [ICrEAMTool createAndAddBiggerButtonForButton:calenderBtn andSEL:@selector(clickCalenderBtn) target:self addTop:15 bottom:0 left:15 right:15 inView:self.bigScrollView];
        
        //第六行
        self.stationView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(CGRectGetMinX(self.stepInTimeView.frame), self.stepInTimeView.bottomEdge+yDistance, CGRectGetWidth(self.stepInTimeView.frame), TitleTFViewHeight) title:@"预约工位" addTarget:nil selector:nil];
        self.stationView.contentTextFeild.placeholder = @"请选择";
        [self.bigScrollView addSubview:self.stationView];
        
        self.workTimeView = [ICMTitleTextFeildView createClickableICMTitleTextFeildViewWithFrame:CGRectMake(self.stationView.rightEdge+xDistanceA, CGRectGetMinY(self.stationView.frame), CGRectGetWidth(self.stationView.frame), TitleTFViewHeight) title:@"预计施工时间" addTarget:nil selector:nil];
        self.workTimeView.contentTextFeild.placeholder = @"请选择";
        [self.bigScrollView addSubview:self.workTimeView];
        
        self.tipsView = [ICMTitleTextFeildView createEditableICMTitleTextFeildViewWithFrame:CGRectMake( self.workTimeView.rightEdge+xDistanceB, CGRectGetMinY(self.stationView.frame), CGRectGetWidth(self.sendCarAddressView.frame), TitleTFViewHeight) title:@"备注"];
        [self.bigScrollView addSubview:self.tipsView];
        
        //分割线
        UIView *firstSeparator = [[UIView alloc] initWithFrame:CGRectMake(self.centerX, yDistance, 1, customerPhoneNumberView.bottomEdge+ActualHeight(10)-yDistance)];
        firstSeparator.backgroundColor = SepColor_gray;
        [self.bigScrollView addSubview:firstSeparator];
        
        UIView *secondSeparetor = [[UIView alloc] initWithFrame:CGRectMake(vinNumberView.x, customerPhoneNumberView.bottomEdge+yDistance, customerPhoneNumberView.rightEdge-vinNumberView.x, 1)];
        secondSeparetor.backgroundColor = SepColor_gray;
        [self.bigScrollView addSubview:secondSeparetor];
        
        UIView *thirdSeparator = [[UIView alloc] initWithFrame:CGRectMake(self.centerX, yDistance+self.centerY, 1, customerPhoneNumberView.bottomEdge+ActualHeight(10)-yDistance)];
        thirdSeparator.backgroundColor = SepColor_gray;
        [self.bigScrollView addSubview:thirdSeparator];
        
        self.bigScrollView.contentSize = CGSizeMake(ScreenWidth, CGRectGetMaxY(self.tipsView.frame));
        [self addSubview:self.bigScrollView];
    }
    return self;
}

#pragma mark    根据model设置界面
- (void)setupAppointmentBasicInfoViewWithBasicModel:(ICMAppointmentBasicInfoModel *)basicInfoModel andOtherModel:(ICMAppointmentOtherInfoModel *)otherInfoModel{
    self.vinNumberView.contentText = basicInfoModel.VIN;
    self.vinNumberView.contentTextFeild.userInteractionEnabled = NO;
    
    NSString *area = @"";
    NSString *plant = @"";
    if (basicInfoModel.LICENSE.length>2) {
        area = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(0, 1)];
        plant = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(1, basicInfoModel.LICENSE.length-1)];
        unsigned char mCode;
        sscanf([area UTF8String], "%c", &mCode);
        if (mCode <= 'Z' && mCode >= 'A') {
            area = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(0, 2)];
            plant = [basicInfoModel.LICENSE substringWithRange:NSMakeRange(2, basicInfoModel.LICENSE.length-2)];
        }
    }
    self.selectAreaView.contentText = area;
    self.plateNumberView.contentText = plant;
    
    self.selectAreaView.userInteractionEnabled = YES;
    self.plateNumberView.userInteractionEnabled = YES;
    
    self.ownerNameView.contentText = basicInfoModel.OWNER_NAME;
    self.invoiceDateView.contentText = (!basicInfoModel.SALES_DATE || [basicInfoModel.SALES_DATE isEqualToString:@"0"] || [basicInfoModel.SALES_DATE doubleValue] < 0)?@"":[ICrEAMTool getDateWithTimeInterval:basicInfoModel.SALES_DATE];
    self.currentMileageView.contentText = basicInfoModel.IN_MILEAGE;
    self.ownerPhoneNumberView.contentText = basicInfoModel.OWNER_MOBILE;
    self.ownerTypeView.contentText = [ICrEAMTool getCodeModelForCode:basicInfoModel.OWNER_PROPERTY].desc;
    self.ownerTypeView.noStr = basicInfoModel.OWNER_PROPERTY;
    self.carTypeView.contentText = [NSString stringWithFormat:@"%@|%@",basicInfoModel.MODEL_CODE,basicInfoModel.MODEL_NAME];
    self.carTypeView.noStr = basicInfoModel.MODEL_CODE;
    self.haveChangeVIN = YES;
    // 油量？？？
    
//    if(IsStrEmpty(self.customerNameView.contentText)){
//        self.customerNameView.contentText = otherInfoModel.CONTACTOR_NAME?otherInfoModel.CONTACTOR_NAME:basicInfoModel.OWNER_NAME;
//    }
//    if(IsStrEmpty(self.customerPhoneNumberView.contentText)){
//        self.customerPhoneNumberView.contentText = otherInfoModel.CONTACTOR_MOBILE?otherInfoModel.CONTACTOR_MOBILE:basicInfoModel.OWNER_MOBILE;
//        
//    }

    
    
    self.customerNameView.contentText = otherInfoModel.CONTACTOR_NAME?otherInfoModel.CONTACTOR_NAME:basicInfoModel.OWNER_NAME;
    self.customerPhoneNumberView.contentText = otherInfoModel.CONTACTOR_MOBILE?otherInfoModel.CONTACTOR_MOBILE:basicInfoModel.OWNER_MOBILE;
    self.sendCarAddressView.contentText = basicInfoModel.DELIVER_ADD;
    
    NSMutableArray *repiarDescs = [NSMutableArray array];
    NSArray *repiarCodes = [otherInfoModel.BOOKING_REPAIR_TYPE componentsSeparatedByString:@";"];
    for (NSString *code in repiarCodes) {
        NSString *desc = [ICrEAMTool getRepiarTypeDescWithRepiarCode:code];
        [repiarDescs PACA_AddObject:desc];
    }
    self.appointmentSubTypeView.contentText = [repiarDescs componentsJoinedByString:@","];
    self.pickUpAddressView.contentText = otherInfoModel.DRIVE_ADD;
    self.tipsView.contentText = otherInfoModel.REMARK;
    
    self.stepInTimeView.contentText = [ICrEAMTool getDateHourAndMinWithTimeInterval:otherInfoModel.BOOKING_COME_TIME];
    self.haveChangeVIN = YES;
    self.serviceAdvisorView.contentText = otherInfoModel.EMPLOYEE_NAME;
    self.SERVICE_ADVISOR = otherInfoModel.SERVICE_ADVISOR;
    self.stationView.contentText = otherInfoModel.LABOUR_POSITION_NAME;//预约工位
    self.EST_REPAIR_TIME = [otherInfoModel.EST_REPAIR_TIME floatValue]==0?@"":otherInfoModel.EST_REPAIR_TIME;
    if ([self.EST_REPAIR_TIME isEqualToString:@""]) {
        self.workTimeView.contentText = @"";
    }else{
        float workTime = [self.EST_REPAIR_TIME floatValue];
        NSString *workTimeText;
        NSInteger workTimeHour = workTime;
        float workTimeMin = workTime - workTimeHour;
        workTimeText = workTimeHour>0?[NSString stringWithFormat:@"%ld小时",workTimeHour]:@"";
        self.workTimeView.contentText = workTimeMin>0?[NSString stringWithFormat:@"%@%ld分钟",workTimeText,((NSInteger)(workTimeMin*60))]:workTimeText;
    }
    self.BOOKING_ORDER_NO = basicInfoModel.BOOKING_ORDER_NO;
    self.RECEPTION_TIME = otherInfoModel.RECEPTION_TIME;
    self.EST_STATION_TIME = [ICrEAMTool getDateHourAndMinSecondWithTimeInterval:otherInfoModel.EST_STATION_TIME];
    self.stationCode = otherInfoModel.LABOUR_POSITION_CODE;
    self.isOnline = [otherInfoModel.RES_TYPE isEqualToString:@"ONLINE"];
}
#pragma mark setIsOnline
- (void)setIsOnline:(BOOL)isOnline{
    _isOnline = isOnline;
    self.selecteStepInTimeView.isOnline = isOnline;
}

+ (instancetype)createICMAppointmentBasicInfoViewWithFrame:(CGRect)frame{
    return [[ICMAppointmentBasicInfoView alloc] initWithFrame:frame];
}

#pragma mark text点击事件
- (void)stepInTimeViewDidSelected:(ICMTitleTextFeildView*)textView{
    [self endEditing:YES];
    if (!self.appointmentSubTypeView.contentText || [self.appointmentSubTypeView.contentText isEqualToString:@""]){
        [self showString:@"请先选择预约业务子类型！" forSeconds:1.5];
        return;
    }
    
//    if (![ICrEAMTool isVW]) {
//        if (self.skEditType) {
//            [self showString:@"预约时间不能更改！" forSeconds:1.5];
//            return;
//        }
//    }
    
    
    
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(stepInTimeViewBackgroundTapAction:)];
    [backgroundView addGestureRecognizer:_tap];
    backgroundView.backgroundColor = BackgroundColor_Tanslucent_black;
    
    [Window addSubview:backgroundView];
    [Window addSubview:self.selecteStepInTimeView];
}
#pragma mark    selecteStepInTimeView
- (ICMSelecteStepInTimeView *)selecteStepInTimeView{
    if (!_selecteStepInTimeView) {
        NSString *appointmentDate = (self.stepInTimeView.contentText&&![self.stepInTimeView.contentText isEqualToString:@""])?self.stepInTimeView.contentText:@"";
        _selecteStepInTimeView = [[ICMSelecteStepInTimeView alloc]initWithFrame:CGRectMake(ActualWidth(37.5), 60, ScreenWidth-ActualWidth(70), ScreenHeight-120) andServer:self.SERVICE_ADVISOR andAppointmentDate:appointmentDate andReceptionTime:_RECEPTION_TIME andStationBeginTime:_EST_STATION_TIME andStationTime:self.EST_REPAIR_TIME andStationCode:self.stationCode andBackTarge:self];
        _selecteStepInTimeView.isOnline = self.isOnline;
        _selecteStepInTimeView.isEditType = !StrIsZero_gdm(_RECEPTION_TIME);
        _selecteStepInTimeView.delegate = self.delegate;
    }
    return _selecteStepInTimeView;
}

#pragma mark    点击维修类型
- (void)clickRepairType{
    [self endEditing:YES];
    if ([self.delegate respondsToSelector:@selector(clickRepairTypeBtn)]) {
        [self.delegate clickRepairTypeBtn];
    }
}
#pragma mark    预约顾问界面背景点击
- (void)stepInTimeViewBackgroundTapAction:(UITapGestureRecognizer*)tap{
    UIView *tapView = tap.view;
    [tapView removeFromSuperview];
    [self.selecteStepInTimeView removeFromSuperview];
    //处理预约时间界面消失后带过来的数据
    [self setupAppointmentText];
}
#pragma mark    预约顾问界面返回按钮
- (void)stepInTimeViewBackButtonAction:(UIButton*)sender{
    [self stepInTimeViewBackgroundTapAction:_tap];
}
#pragma mark    转换时长
- (void)setupAppointmentText{
    if (self.selecteStepInTimeView.serverTimeModel.firstTimeDesc) {
        self.stepInTimeView.contentText = [NSString stringWithFormat:@"%@ %@",self.selecteStepInTimeView.stepInTimeView.contentText,self.selecteStepInTimeView.serverTimeModel.firstTimeDesc];
    }else{
        self.stepInTimeView.contentText = @"";
    }
    self.haveChangeVIN = YES;
    self.serviceAdvisorView.contentText = self.selecteStepInTimeView.serviceAdvisorView.contentText;
    self.SERVICE_ADVISOR = self.selecteStepInTimeView.userId;
    self.stationCode = self.selecteStepInTimeView.stationCode;
    self.stationView.contentText = self.selecteStepInTimeView.selectedStationTitle;
    self.EST_REPAIR_TIME = self.selecteStepInTimeView.workingHour;
    if ([self.EST_REPAIR_TIME isEqualToString:@""]) {
        self.workTimeView.contentText = @"";
    }else{
        float workTime = [self.EST_REPAIR_TIME floatValue];
        NSString *workTimeText;
        NSInteger workTimeHour = workTime;
        float workTimeMin = workTime - workTimeHour;
        workTimeText = workTimeHour>0?[NSString stringWithFormat:@"%ld小时",workTimeHour]:@"";
        self.workTimeView.contentText = workTimeMin>0?[NSString stringWithFormat:@"%@%ld分钟",workTimeText,((NSInteger)(workTimeMin*60))]:workTimeText;
    }
}

//button点击
- (void)clickCarInfoBtn{
    if ([self.delegate respondsToSelector:@selector(clickCarInfoBtn)]) {
        [self.delegate clickCarInfoBtn];
    }
}

- (void)clickMonitorBtn{
    if ([self.delegate respondsToSelector:@selector(clickMonitorBtn)]) {
        [self.delegate clickMonitorBtn];
    }
}

- (void)clickCarOwnerBtn{
    if ([self.delegate respondsToSelector:@selector(clickCarOwnerBtn)]) {
        [self.delegate clickCarOwnerBtn];
    }
}

- (void)clickCalenderBtn{
    [self stepInTimeViewDidSelected:self.stepInTimeView];
}

#pragma mark    输入框输入结束
- (void)editableViewDidEndEdit:(ICMTitleTextFeildView *)sender{
    if (sender == self.vinNumberView) {
        self.haveChangeVIN = YES;
        if ([self.delegate respondsToSelector:@selector(licenseDidEndEdit:type:)]) {
            [self.delegate licenseDidEndEdit:sender type:@"0"];
        }
    }else{
        if ([self.delegate respondsToSelector:@selector(licenseDidEndEdit:type:)]) {
            [self.delegate licenseDidEndEdit:sender type:@"1"];
        }
    }
}
#pragma mark    点击车牌地
- (void)clickSelectAreaView:(ICMTitleTextFeildView *)view {
    [self addSubview:self.selectAreaPrefixView];
}
#pragma mark selectAreaPrefixView
- (SelectAreaPrefixView *)selectAreaPrefixView {
    if (!_selectAreaPrefixView) {
        _selectAreaPrefixView = [[SelectAreaPrefixView alloc] initWithFrame:CGRectMake(ActualWidth(207), self.selectAreaView.bottomEdge, ActualWidth(630), ActualHeight(185))];
        _selectAreaPrefixView.delegate = self;
    }
    return _selectAreaPrefixView;
}

- (void)setBOOKING_ORDER_NO:(NSString *)BOOKING_ORDER_NO{
    _BOOKING_ORDER_NO = BOOKING_ORDER_NO;
    if ([self.delegate respondsToSelector:@selector(cancelSaveCanAction:)]) {
        [self.delegate cancelSaveCanAction:(BOOKING_ORDER_NO && ![BOOKING_ORDER_NO isEqualToString:@""])];
    }
}

#pragma mark    选取车牌地
- (void)didSelectAreaPrefix:(NSString *)prefix{
    if ([prefix isEqualToString:@"其他"]) {
        [Window addSubview:self.inputAreaView];
        [self.inputAreaView.inputAreaTextView.contentTextFeild becomeFirstResponder];
        return;
    }
//    BOOL isChange = ![self.selectAreaView.contentText isEqualToString:prefix];
    self.selectAreaView.contentText = prefix;
    [self.plateNumberView.contentTextFeild becomeFirstResponder];
//    if (isChange&&self.plateNumberView.contentText.length>5&&[self.delegate respondsToSelector:@selector(licenseDidEndEdit:type:)]) {
//        [self.delegate licenseDidEndEdit:self.plateNumberView type:@"1"];
//    }
}

- (UIView *)inputAreaView{
    if (!_inputAreaView) {
        _inputAreaView = [ICMInputAreaView createInputAreaView];
        _inputAreaView.delegate = self;
    }
    return _inputAreaView;
}

#pragma mark    其他车牌地输入结束
- (void)inputAreaViewWillDisappearWithText:(NSString *)text{
    [self didSelectAreaPrefix:text];
}

- (NSString *)RECEPTION_TIME{
    NSString *timeView_RECEPTION_TIME = self.selecteStepInTimeView.RECEPTION_TIME;
    if ([timeView_RECEPTION_TIME isEqualToString:@"empty"]) {
        return _RECEPTION_TIME;
    }
    return self.selecteStepInTimeView.RECEPTION_TIME;
}

- (NSString *)EST_STATION_TIME{
    NSString *timeView_EST_STATION_TIME = self.selecteStepInTimeView.EST_STATION_TIME;
    if ([timeView_EST_STATION_TIME isEqualToString:@"empty"]) {
        return _EST_STATION_TIME;
    }
    return self.selecteStepInTimeView.EST_STATION_TIME;
}

- (NSString *)VIN_FOR_ACTIVITY{
    return self.vinNumberView.contentText?self.vinNumberView.contentText:@"";
}

-(void)cleanAllTextFieldText{

    //清除车辆信息
    self.carModel.vinNum = @"";
    self.carModel.brand = @"";
    self.carModel.brandName = @"";
    self.carModel.carKei = @"";
    self.carModel.carKeiName = @"";
    self.carModel.carType = @"";
    self.carModel.carTypeName = @"";
    self.carModel.isOurBranch = @"";
    self.carModel.carNum = @"";
    self.carModel.useNature = @"";
    self.carModel.carNature = @"";
    self.carModel.carUses = @"";
    self.carModel.parchaseDate = @"";
    self.carModel.lastMillions = @"";
    self.carModel.perMillions = @"";
    self.carModel.guaranteeEndDate = @"";
    self.carModel.guaranteeEndMillions = @"";
    self.carModel.nextCheckDate = @"";
    self.carModel.insuranceCompany = @"";
    self.carModel.HQ_VW_CARD_ID = @"";
    self.carModel.adviserCode = @"";
    self.carModel.adviserName = @"";
    self.carModel.VEHICLE_LIFE_STATUS = @"";
    self.carModel.SERIES_CODE = @"";
    self.carModel.SERIES_NAME = @"";
    self.carModel.OWNER_NO = @"";
    self.carModel.SALES_DATE = @"";
    self.carModel.LABOUR_PRICE = @"";
    //车主模型
    self.personModel.OWNER_NO = @"";
    self.personModel.ownerName = @"";
    self.personModel.gender = @"";
    self.personModel.birthday = @"";
    self.personModel.ownerType = @"";
    self.personModel.cerType = @"";
    self.personModel.cerNum = @"";
    self.personModel.province = @"";
    self.personModel.city = @"";
    self.personModel.district = @"";
    self.personModel.phoneNum = @"";
    self.personModel.address = @"";
    self.personModel.adviserCode = @"";
    self.personModel.adviserName = @"";
    self.personModel.vwOneHome = @"";
    self.personModel.oneHomeNum = @"";
    self.personModel.profType = @"";
    self.personModel.familyIncome = @"";
    self.personModel.hobby = @"";
    self.personModel.consumeProperty = @"";
    self.personModel.mannerProperty = @"";
    self.personModel.interestedPresent = @"";
    self.personModel.interestedActivity = @"";
    self.personModel.advancedReceived = @"";
    self.personModel.amount = @"";
    self.personModel.INDUSTRY_FIRST = @"";
    self.personModel.CONTACTOR_MOBILE = @"";
    self.personModel.CONTACTOR_NAME = @"";
    self.personModel.CONTACTOR_ADDRESS = @"";
    
    
    
    self.ownerNameView.contentText = @"";
    self.invoiceDateView.contentText = @"";
    self.currentMileageView.contentText = @"";
    self.ownerPhoneNumberView.contentText = @"";
    self.ownerTypeView.contentText = @"";
    self.carTypeView.contentText = @"";
    self.customerNameView.contentText = @"";
    self.customerPhoneNumberView.contentText = @"";
    self.carTypeView.noStr = @"";
    
//    self.ownerNameView.btnEnAble = YES;
//    self.ownerPhoneNumberView.btnEnAble = YES;
//    self.ownerNameView.backgroundColor = TextFeildBackgroundColor_OffWhite;
//    self.ownerPhoneNumberView.backgroundColor = TextFeildBackgroundColor_OffWhite;
}
@end







